package cn.gyouzhe.source;

import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 来源生产器
 *
 * @author wangchuan
 * @datetime 2018/2/25 21:46
 */
@Component
public class SourceFactory {
    /**
     * 所有来源
     * @return
     */
    private List<Source> sources() {
        return Arrays.asList(new DataokeSource());
    }

    /**
     * 获取执行器service
     * @param size
     * @return
     */
    private ExecutorService executorService(int size) {
        return Executors.newFixedThreadPool(size);
    }

    /**
     * 启动所有来源
     */
    @PostConstruct
    public void start() {
        List<Source> sources = sources();
        ExecutorService executorService = executorService(sources.size());
        sources.forEach(executorService::submit);
    }
}
